﻿@using RuoVea.ExDto
@using RuoVea.OmiLog.Language
@using RuoVea.OmiLog.Attributes
@using RuoVea.OmiLog.Options
@{
    AppConfig config = ConfigManages.Config ?? new AppConfig();
}
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@Html.Raw(i18n.access_log)</title>
    <link href="~/ruoveaui/xg6rvft8p/avue/index.css" rel="stylesheet" />
    <link href="~/ruoveaui/xg6rvft8p/elementui/index.min.css" rel="stylesheet" />
    <style> .el-button [class*="el-icon-"] + span { margin-left: 1px !important; } </style>
</head>
<body>
    <div id="app" v-cloak>
        <avue-crud :data="tableData" :option="option" :page.sync="pageOption" :table-loading="loading"
                   v-on:refresh-change="refreshChange"
                   v-on:search-change="searchChange"
                   v-on:search-reset="resetChange"
                   :cell-style="cellStyle"
                   v-on:on-load="onLoad">
            <template slot="avatar" slot-scope="scope">
                <el-avatar shape="circle" :src="scope.row.avatar">{{scope.row.account}} </el-avatar>
            </template>

            <template slot="record" slot-scope="scope">
                <modify-record :data="scope.row"></modify-record>
            </template>
             <template slot="menuRight" slot-scope="{size}">
                <el-button icon="el-icon-delete" type="danger" circle :size="size" v-on:click="handleDeleteAll" v-if="option.clearBtn"></el-button>
              </template>
        </avue-crud>
    </div>
    <script src="~/ruoveaui/xg6rvft8p/vue/vue.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/index.i18n.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/index.lang.js"></script>
    <script>
        Vue.prototype.i18n.messages.zhCN = { ...Vue.prototype.i18n.messages.zhCN, ...{"failure": "失败", "success": "成功", "name": "名称", "execution_success": "执行成功", "browser": "浏览器", "address": "地址", "access_type": "访问类型", "access_time": "访问时间", "operator": "操作人", "login": "登录", "logout": "登出", "register": "注册", "change_password": "改密", "third_party_auth_login": "三方授权登陆" } };         
        Vue.prototype.i18n.messages.en = { ...Vue.prototype.i18n.messages.en, ...{ "failure": "Failure", "success": "Success", "name": "Name", "execution_success": "Execution Success", "browser": "Browser", "address": "Address", "access_type": "Access Type", "access_time": "Access Time", "operator": "Operator", "login": "Login", "logout": "Logout", "register": "Register", "change_password": "Change Password", "third_party_auth_login": "Third-party Auth Login"} };         
        Vue.prototype.i18n.messages.fr = { ...Vue.prototype.i18n.messages.fr, ...{ "failure": "Échec", "success": "Succès", "name": "Nom", "execution_success": "Exécution réussie", "browser": "Navigateur", "address": "Adresse", "access_type": "Type d'accès", "access_time": "Heure d'accès", "operator": "Opérateur", "login": "Connexion", "logout": "Déconnexion", "register": "Inscription", "change_password": "Changer le mot de passe", "third_party_auth_login": "Connexion avec authentification tierce partie" } };         
        Vue.prototype.i18n.messages.ja = { ...Vue.prototype.i18n.messages.ja, ...{ "failure": "失敗", "success": "成功", "name": "名称", "execution_success": "実行成功", "browser": "ブラウザ", "address": "アドレス", "access_type": "アクセス種類", "access_time": "アクセス時間", "operator": "操作者", "login": "ログイン", "logout": "ログアウト", "register": "登録", "change_password": "パスワード変更", "third_party_auth_login": "サードパーティ認証ログイン"} };         
        Vue.prototype.i18n.messages.vi = { ...Vue.prototype.i18n.messages.vi, ...{"failure": "Thất bại", "success": "Thành công", "name": "Tên", "execution_success": "Thực hiện thành công", "browser": "Trình duyệt", "address": "Địa chỉ", "access_type": "Loại truy cập", "access_time": "Thời gian truy cập", "operator": "Người thực hiện", "login": "Đăng nhập", "logout": "Đăng xuất", "register": "Đăng ký", "change_password": "Đổi mật khẩu", "third_party_auth_login": "Đăng nhập bằng xác thực bên thứ ba" } };
        Vue.prototype.i18n.messages.zhTW = { ...Vue.prototype.i18n.messages.zhTW, ...{ "failure": "失败", "success": "成功", "name": "名称", "execution_success": "执行成功", "browser": "浏览器", "address": "地址", "access_type": "访问类型", "access_time": "访问时间", "operator": "操作人", "login": "登录", "logout": "登出", "register": "注册", "change_password": "改密", "third_party_auth_login": "三方授权登陆" } };
    </script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/index.min.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/lang/zhCN.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/lang/en.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/lang/fr.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/lang/ja.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/lang/vi.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/elementui/lang/zhTW.js"></script>
    <script>Vue.prototype.$baseURL = "@config?.PrefixRoute";</script>
    <script src="~/ruoveaui/xg6rvft8p/vue/axios.min.min.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/vue/vue-i18n.min.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/avue/avue.min.js"></script>
    <script src="~/ruoveaui/xg6rvft8p/avue/avue.min.option.js"></script>
    <script>
        var successDicData = [{ label: `${Vue.prototype.i18n.t('failure')}`, value: 0, }, { label: `${Vue.prototype.i18n.t('success')}`, value: 1, }];
        var visTypeDicData = [ { label: `${Vue.prototype.i18n.t('login')}`, value: 0, },  { label: `${Vue.prototype.i18n.t('logout')}`, value: 1, },  { label: `${Vue.prototype.i18n.t('register')}`, value: 2, },  { label: `${Vue.prototype.i18n.t('change_password')}`, value: 3, },  { label: `${Vue.prototype.i18n.t('third_party_auth_login')}`, value: 4, }, ];
        new Vue({
            el: '#app',
            data() {
                return {

                    name: "logvis",
                    pageUrl: "/logvis/pages", 

                    pageOption: {
                        total: 0,
                        page: 1,
                        pageSize: 10
                    },

                    loading: true,
                    btnLoading: false,
                    tableData: [],
                    searchParams: {},

                    searchShowBtn: false,
                    refreshBtn: false,
                    option: {
                        searchShowBtn: Permissions.avePermission(`sysLogVis:pages`),
                        refreshBtn: Permissions.avePermission(`sysLogVis:pages`),
                        clearBtn: Permissions.avePermission(`sysLogVis:clear`),
                        rowKey: 'id',
                        columnBtn: false,
                        searchShow: false,
                        addBtn: false,
                        menu: false,
                        editBtn: false,
                        delBtn: false,
                        viewBtn: false,
                        column: [
                            { prop: "id", label: `${this.i18n.t('primary_key')}`, search: false, hide: true, type: "number", display: false, showColumn: false, },

                            { prop: "name", label: `${this.i18n.t('name')}`, search: true, hide: false, type: "input",width:80 },
                            { prop: "success", label: `${this.i18n.t('execution_success')}`, search: true, hide: false, type: "select", overHidden: true, width: 80,dicData:successDicData},
                            { prop: "ip", label: `IP`, search: false, hide: false, type: "input", overHidden: true, width: 120,},
                            { prop: "browser", label: `${this.i18n.t('browser')}`, search: false, hide: false, type: "input", overHidden: true, },
                            { prop: "location", label: `${this.i18n.t('address')}`, search: false, hide: false, type: "input", overHidden: true, },
                            { prop: "os", label: `os`, search: false, hide: false, type: "input", },
                            { prop: "visType", label: `${this.i18n.t('access_type')}`, search: true, hide: false, type: "select",dicData:visTypeDicData },
                            { prop: "visTime", label: `${this.i18n.t('access_time')}`, search: true, hide: false, type: "datetime",searchRange: true, },
                            { prop: "account", label: `${this.i18n.t('operator')}`, search: false, hide: false, type: "input", overHidden: true,width: 120,},
                        ]
                    }
                }
            },
            created() {
            },
            methods: {
                cellStyle({ row, column, rowIndex, columnIndex }) {
                    if (columnIndex == 2) {
                        if (row.success == 1) {
                            return { color: '#409eff', }
                        }
                        else {
                            return { color: '#f56c6c', }
                        }
                    }
                },
                hasPermission(key) {
                    if (key === 'columnBtn' || key === 'menu' || key === 'refreshBtn') return true;
                    else return Permissions.avePermission(`${this.name}:${key}`);
                },
                getPermission(key) {
                    return Permissions.avePermission(`${key}`);
                },
                onLoad(page, done) {
                    if (this.searchParams.visTime) {
                        const [BeginTime, EndTime] = this.searchParams.visTime
                        var data = { ...page, ...this.searchParams };
                        data.BeginTime = BeginTime;
                        data.EndTime = EndTime;
                    }
                    else {
                        var data = { ...page, ...this.searchParams };
                    }
                    this.$http.post(`${this.pageUrl}`, data).then((res) => {
                        this.tableData = res.rows;
                        this.pageOption.total = res.totalRows;
                        this.loading = false;
                        if (done) { done(); }
                    }).catch(e => {
                        this.loading = false;
                        console.log(e);
                    });
                },
                searchChange(params, done) {
                    this.searchParams = params;
                    this.pageOption.page = 1;
                    this.onLoad(this.pageOption, done);
                },
                resetChange(item) {
                    this.searchParams = item;
                    this.pageOption.page = 1;
                    this.onLoad(this.pageOption);
                },
                refreshChange() { this.onLoad(this.pageOption); },
                handleDeleteAll() {
                    this.$confirm(this.i18n.t('confirmdelete'), this.i18n.t('tips'), { confirmButtonText: this.i18n.t('determine'), cancelButtonText: this.i18n.t('cancel'), type: 'error', customClass: "elmessagebox" }).then(() => {
                        this.$http.post("/logdiff/clear").then((res) => {
                            if (!res) {
                                this.$message({ message:`${this.i18n.t('submit_success')}`, center: true, type: 'success' });
                                this.onLoad();
                            }
                        });
                    }).catch(_ => { console.info(_); })
                },
            }
        });
    </script>
</body>
</html>